package graphics.rasterizing.shading;

import static util.MatrixOperationsF.add;
import static util.MatrixOperationsF.cross_product;
import static util.MatrixOperationsF.multiply;
import static util.MatrixOperationsF.negate;
import static util.MatrixOperationsF.normalize;
import graphics.rasterizing.LightSource;
import graphics.rasterizing.model.Triangle;

public class SimpleShader implements Shader {
	private LightSource _source;

	public SimpleShader(LightSource source) {
		_source = source;
	}

	@Override
	public float[] shade(float alpha, float beta, float gamma, Triangle tri) {
		// calculate tri normal
		float[] normal = normalize(cross_product(
				add(tri.tri[1], negate(tri.tri[0])),
				add(tri.tri[2], negate(tri.tri[0]))));
		float value = Math.abs(multiply(normal,
				normalize(_source.getDirection())));
		return multiply(tri.colors[0], value);
	}

}
